﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using Microsoft.Practices.Composite.Presentation.Commands;

namespace WorldIndex.Modules.Countries.Views
{
    public class CountryListViewModel
    {
        //private readonly WorldIndexContext _countriesServices; 

        public CountryListViewModel()
        {
            Countries = new ObservableCollection<Country>();
            SignalSomething = new DelegateCommand<object>(
                 executeCommand, canHandleButtonCommand);
        }

        public void InitView()
        {
            if (CountryService != null)
            {
                //var context = new WorldIndexContext();
                //context.Load(context.GetMdgCountryQuery());
                //context.PropertyChanged += new PropertyChangedEventHandler(context_PropertyChanged);
            }
        }

        public ObservableCollection<Country> Countries { get; set; }


        public ICountryService CountryService { get; set; }

        public DelegateCommand<object> SignalSomething
        {
            get;
            set;
        }

        public bool canHandleButtonCommand(object o)
        {
            return true;
        }

        public void executeCommand(object o)
        {
            if (CountryService != null)
            {
                //var context = new WorldIndexContext();
                //context.Load(context.GetMdgCountryQuery());
                //context.PropertyChanged += new PropertyChangedEventHandler(context_PropertyChanged);
            }
        }

        void context_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //var context = (WorldIndexContext) sender;
            //Countries.Clear();
            //var countries = context.MdgCountries;

            //foreach (var c in countries)
            //{
            //    Countries.Add(new Country { Name = c.Name, Capital = "null" });
            //}
        }
    }
}
